﻿namespace JxcLite.Services;

public interface IFinanceService : IService
{
    Task<PagingResult<AccountInfo>> QueryAccountsAsync(PagingCriteria criteria);
    Task<AccountInfo> GetDefaultAccountAsync(string type);
    Task<Result> DeleteAccountsAsync(List<AccountInfo> models);
    Task<Result> SaveAccountAsync(UploadInfo<AccountInfo> info);
}

[Client]
class FinanceClient(HttpClient http) : ClientBase(http), IFinanceService
{
    public Task<PagingResult<AccountInfo>> QueryAccountsAsync(PagingCriteria criteria)
    {
        return Http.QueryAsync<AccountInfo>("/Finance/QueryAccounts", criteria);
    }

    public Task<AccountInfo> GetDefaultAccountAsync(string type)
    {
        return Http.GetAsync<AccountInfo>($"/Finance/GetDefaultAccount?type={type}");
    }

    public Task<Result> DeleteAccountsAsync(List<AccountInfo> infos)
    {
        return Http.PostAsync("/Finance/DeleteAccounts", infos);
    }

    public Task<Result> SaveAccountAsync(UploadInfo<AccountInfo> info)
    {
        return Http.PostAsync("/Finance/SaveAccount", info);
    }
}